<?php

/*
 * 作者:liuleyi
 * 功能描述:VIP控制器
 * 修改记录
 * 修改时间   修改人     修改描述
 */

namespace Admin\Controller;

use Think\Controller;

class VIPController extends Controller {

    public function add() {
        if (!empty($_POST)) {

            $func = new \Admin\Func\Func909010101(I('VIPNo'), I('VIPLoginCode'), I('VIPName'), I('VIPNickName'), I('VIPPhoneNo'), I('Sex'), I('BirthDay'), I('Mail'), I('VIPType'), I('VIPLevel'), I('VIPFigthValue'), I('VIPIMG'));

            if ($func->execute() === false) {
                $this->error("新增失败:" . $func->getErrMsg());
            } else {
                // $this->display();
                $this->success('新增成功！');
            }
            //  $this->display();
        } else {
            $this->assign('GV_Enum', $GLOBALS['GV_Enum']);
            $this->display();
        }
    }

    public function del($VIPNo) {
        $func = new \Admin\Func\Func909010103($VIPNo);
        if ($func->execute() === false) {
            $this->error('删除失败' . $func->getErrMsg());
        } else {
            $this->redirect('VIP/lst');
        }
    }

    public function edit($VIPNo) {

        if (!empty($_POST)) {

            if (!empty($_FILES)) {
                $upload = new \Think\Upload(); // 实例化上传类
                //$upload->exts = array('jpg', 'gif', 'png', 'jpeg'); // 设置附件上传类型
                $upload->saveName = array('uniqid', '');
                $upload->rootPath = FILE_ROOT_PATH; // 设置附件上传目录    // 上传单个文件
                $upload->savePath = FILE_SAVE_PATH; // 设置附件上传目录    // 上传单个文件
                $info = $upload->uploadOne($_FILES['VIPIMG']);
                $image = new \Think\Image();
                $bigimg = $info['savepath'] . $info['savename'];
                //open();打开图像资源，通过路径名找到图像
                $srcimg = $upload->rootPath . $bigimg;
                $image->open($srcimg);
                $image->thumb(150, 150);  //按照比例缩小
                $smallimg = $info['savepath'] . "small_" . $info['savename'];
                $image->save($upload->rootPath . $smallimg);
              //  $_POST['goods_small_img'] = $smallimg;
                
                if (!$info) {
                    $this->error($upload->getError());
                } else {// 上传成功 获取上传文件信息  
                    // $this->success('编辑成功！' . $info['savename']);
                    $func = new \Admin\Func\Func909010102(I('VIPNo'), I('VIPLoginCode'), I('VIPName'), I('VIPNickName'), I('VIPPhoneNo'), I('Sex'), I('BirthDay'), I('Mail'), I('VIPType'), I('VIPLevel'), I('VIPFigthValue'), $info['savepath'] . $info['savename'],$smallimg);
                    if ($func->execute() === false) {
                        $this->error("编辑失败:" . $func->getErrMsg());
                    } else {

                        $this->success('编辑成功！');
                    }
                }
            } else {
                $func = new \Admin\Func\Func909010102(I('VIPNo'), I('VIPLoginCode'), I('VIPName'), I('VIPNickName'), I('VIPPhoneNo'), I('Sex'), I('BirthDay'), I('Mail'), I('VIPType'), I('VIPLevel'), I('VIPFigthValue'), '','');
                if ($func->execute() === false) {
                    $this->error("编辑失败:" . $func->getErrMsg());
                } else {
                    $this->success('编辑成功！');
                }
            }
        } else {
            $func = new \Admin\Func\Func909010104($VIPNo);
            if ($func->execute() === false) {
                $this->error('查询失败:' . $func->getErrMsg());
            } else {
// show_bug($func->getRst()[0]);
                $this->assign('post', $func->getRst()[0]);
                $this->assign('GV_Enum', $GLOBALS['GV_Enum']);
                $this->display();
            }
        }
    }

    public function lst() {
        $func = new \Admin\Func\Func909010105(I('VIPLoginCode'), I('VIPName'), I('VIPNickName'), I('VIPPhoneNo'), I('Sex'), I('BirthDay'), I('Mail'), I('VIPType'), I('VIPLevel'));
        if ($func->execute() === false) {
            $this->error('查询失败:' . $func->getErrMsg());
        } else {
            $this->assign('lst', $func->getRst());
        }
        $this->assign('GV_Enum', $GLOBALS['GV_Enum']);
        $this->display();
    }

}
